/*
 * Copyright  bocmbci
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import List from '@ohos.util.List';

export class PluginResult{

  private status: number;
  private messageType: number;
  private keepCallback = false;
  private strMessage: string;
  private encodedMessage: string;
  private multipartMessages: List<PluginResult>;

  constructor(status, message) {
    this.status = status;
    this.strMessage = message;
    this.encodedMessage = message;
  }

  getStatus(){
    return this.status;
  }

  getMessageType(): number {
    return this.messageType;
  }

  getStrMessage(): string{
    return this.strMessage;
  }

  getMessage(): string{
    return this.encodedMessage;
  }

  getMultipartMessagesSize(): number{
    return this.multipartMessages ? this.multipartMessages.length : 0;
  }

  getMultipartMessage(index: number): PluginResult | undefined {
    if (this.multipartMessages && index >= 0 && index < this.multipartMessages.length) {
      return this.multipartMessages[index];
    } else {
      return undefined; // 或者返回其他默认值或抛出异常等处理方式
    }
  }

  getKeepCallback(){
    return this.keepCallback
  }
}

export enum PluginResultStatus {
  NO_RESULT,
  OK,
  CLASS_NOT_FOUND_EXCEPTION,
  ILLEGAL_ACCESS_EXCEPTION,
  INSTANTIATION_EXCEPTION,
  MALFORMED_URL_EXCEPTION,
  IO_EXCEPTION,
  INVALID_ACTION,
  JSON_EXCEPTION,
  ERROR
}
